package com.pubinfo.passbook.task.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.eip.dubbo.service.ReceiveTaskInfoService;
import com.pubinfo.passbook.common.model.bo.eip.ReceiveTask;
import com.pubinfo.passbook.common.model.bo.eip.ReceiveTaskParam;
import com.pubinfo.passbook.common.model.bo.eip.ReceiveTaskResult;
import com.pubinfo.passbook.task.EipTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class EipTaskServiceImpl implements EipTaskService {
  @Resource
  ReceiveTaskInfoService infoService;
  
  /**
   * 待办更新接口
   *
   * @param taskParams
   * @return
   */
  @Override
  public ReceiveTaskResult receiveTaskInfo(List<ReceiveTaskParam> taskParams) {
    List<Map<String, String>> receiveTasks = ReceiveTask.toReceiveTaskList(taskParams, "Received");
    return sendTask(receiveTasks);
  }
  
  private ReceiveTaskResult sendTask(List<Map<String, String>> receiveTasks) {
    Map<String, String> resultMap = infoService.receiveTaskInfo("dzpjbz", receiveTasks);
    ReceiveTaskResult result = JSONObject.toJavaObject(JSON.parseObject(JSON.toJSONString(resultMap)), ReceiveTaskResult.class);
    return result;
  }
  
  @Override
  public ReceiveTaskResult finishedTask(String taskId) {
    List<Map<String, String>> receiveTasks = ReceiveTask.toReceiveTask(taskId, "Finished");
    return sendTask(receiveTasks);
  }
//
//  @Override
//  public Map<String, String> pushTodoNum(Map<String, Object> var1) {
//    return null;
//  }

}
